<template>
  <div class="wrapper">
    <!-- <Anchor :labelList="labels" activeId="row-01" labelWidth="100">
      <div class="line" id="row-01">
        <CasePlanInfoBase
          ref="CasePlanInfoBase"
          v-model="value"
          @formchange="CasePlanInfoBaseChange"
        />
      </div>
      <div class="line" id="row-02">
        <CaseExecuteInfoBase
          ref="CaseExecuteInfoBase"
          v-model="value"
          @formchange="CaseExecuteInfoBaseChange"
        />
      </div>
      <div class="line" id="row-03">
        <CaseSummaryInfoBase
          ref="CaseSummaryInfoBase"
          v-model="value"
          @formchange="CaseSummaryInfoBaseChange"
        />
      </div>
      <div class="line" id="row-04">
        <BusinesOpinions ref="BusinesOpinions" v-model="value" @formchange="BusinesOpinionsChange" />
      </div>
      <div class="line" id="row-05">
        <HistorySH v-model="value" />
      </div>
    </Anchor>-->
     <BreakSpace :label="labels[0].title" :containerStyle="{ marginBottom: '10px' }" />
    <CaseBasicsInfoBase ref="CaseBasicsInfoBase" v-model="value"  />
    <BreakSpace :label="labels[1].title" :containerStyle="{ marginBottom: '10px' }" />
    <CasePlanInfoBase ref="CasePlanInfoBase" v-model="value" />
    <BreakSpace :label="labels[2].title" :containerStyle="{ marginBottom: '10px' }" />
    <CaseExecuteInfoBase
      ref="CaseExecuteInfoBase"
      v-model="value"
    />
    <BreakSpace :label="labels[3].title" :containerStyle="{ marginBottom: '10px' }" />
    <CaseSummaryInfoBase
      ref="CaseSummaryInfoBase"
      v-model="value"
     
    />
    <!-- <BreakSpace :label="labels[4].title" :containerStyle="{ marginBottom: '10px' }" />
    <ReportInfoBase ref="ReportInfoBase" v-model="value" @formchange="ReportInfoBaseChange" /> -->
    <BreakSpace :label="labels[4].title" :containerStyle="{ marginBottom: '10px' }" />
    <BusinesOpinions ref="BusinesOpinions" v-model="value" @formchange="BusinesOpinionsChange" />
    <BreakSpace :label="labels[5].title" :containerStyle="{ marginBottom: '10px' }" />
    <HistorySH v-model="value" />

    <div class="dialogBottmView">
      <el-button @click="closeDialog">关 闭</el-button>
  
    </div>
  </div>
</template>

<script>
import { authority } from '@/utils/authMixin';
import { dictionary } from '@/utils/dictMixin';
import CaseBasicsInfoBase from './CaseBasicsInfoBase'; //项目基本信息
import CasePlanInfoBase from './CasePlanInfoBase'; //项目计划信息
import CaseExecuteInfoBase from './CaseExecuteInfoBase'; //项目执行信息
import CaseSummaryInfoBase from './CaseSummaryInfoBase'; //项目总结材料
// import ReportInfoBase from './ReportInfoBase'; //项目报备信息
import BusinesOpinions from './BusinesOpinions'; //事业部意见
import HistorySH from './HistorySH'; //历史审核记录
import { passCaseSummary, updateCaseSummaryPass } from '@/api/cms-api/projectOperating/plan/index';
import * as types from '@/api/cms-api/projectOperating/plan/types';
export default {
  mixins: [authority, dictionary],
  components: {
    CaseBasicsInfoBase,
    CasePlanInfoBase,
    CaseExecuteInfoBase,
    CaseSummaryInfoBase,
    // ReportInfoBase,
    BusinesOpinions,
    HistorySH
  },
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      labels: [
        { title: '项目基本信息', id: 'row-01' },
        { title: '项目计划信息', id: 'row-02' },
        { title: '项目执行信息', id: 'row-03' },
        { title: '项目总结材料', id: 'row-04' },
        // { title: '项目报备信息', id: 'row-05' },
        { title: '事业部意见', id: 'row-06' },
        { title: '历史审核记录', id: 'row-07' }
      ],
      passLoading: false,
      rejectLoading: false,
      refuseLoading: false
    };
  },
  methods: {
    //拒绝
    async refuseDialog() {
      //取数据
      let allData = { ...this.value };
      //@4 事业部意见
      this.$refs.BusinesOpinions.$refs.formPanel.excuteFormData(this.$refs.BusinesOpinions.$refs.formPanel.form);
      allData = Object.assign(allData, this.$refs.BusinesOpinions.$refs.formPanel.form);
      //项目计划总结ID
      allData = Object.assign(allData, { planId: this.value.row.planId });
      //日志状态拒绝
      allData = Object.assign(allData, { reviewStatus: 25311011 });
      //项目计划总结状态 总结已拒绝
      allData = Object.assign(allData, { planStatus: 25311011 });
      //经销商简称
      allData = Object.assign(allData, { dealerShortname: this.value.row.dealerShortname });
      if (allData.overruleReason == '') {
        this.$notify.warning({ title: '提示信息', message: '事业部意见中事业部评价必填!' });
        return;
      }
      this.refuseLoading = true;
      let res = {};
      let res1 = {};
      //保存事业部意见
      res = await passCaseSummary(allData);
      //修改总结状态已通过
      res1 = await updateCaseSummaryPass(allData, this.value.row.planId);
      if (res1.resultCode === 200 && res.resultCode === 200) {
        this.refuseLoading = false;
        this.$notify.success({ title: '提示信息', message: '已拒绝!' });
        this.closeDialog('refresh');
      }
    },
    //驳回（验证事业部评价）
    rejectDialog() {
      this.$refs.BusinesOpinions.saveDialog();
    },
    async BusinesOpinionsChange(data) {
      //项目计划总结ID
      data = Object.assign(data, { planId: this.value.row.planId });
      //日志状态驳回
      data = Object.assign(data, { reviewStatus: 25311010 });
      //项目计划总结状态 总结已驳回
      data = Object.assign(data, { planStatus: 25311010 });
      //经销商简称
      data = Object.assign(data, { dealerShortname: this.value.row.dealerShortname });
      let res = {};
      let res1 = {};
      if (data.overruleReason == '') {
        this.$notify.warning({ title: '提示信息', message: '事业部意见中事业部评价必填!' });
        return;
      }
      this.rejectLoading = true;
      //保存事业部意见
      res = await passCaseSummary(data);
      //修改总结状态已驳回
      res1 = await updateCaseSummaryPass(data, this.value.row.planId);
      if (res.resultCode === 200 && res1.resultCode === 200) {
        this.rejectLoading = false;
        this.$notify.success({ title: '提示信息', message: '已驳回!' });
        this.closeDialog('refresh');
      }
    },
    //通过(不验证事业部评价)
    async passDialog() {
      //取数据
      let allData = { ...this.value };
      //@4 事业部意见
      this.$refs.BusinesOpinions.$refs.formPanel.excuteFormData(this.$refs.BusinesOpinions.$refs.formPanel.form);
      allData = Object.assign({}, this.$refs.BusinesOpinions.$refs.formPanel.form, allData);
      //事业部评价清空
      if (allData.overruleReason == this.$refs.BusinesOpinions.overruleReasonFromDB) {
        allData.overruleReason = '';
      }
      //项目计划总结ID
      allData = Object.assign(allData, { planId: this.value.row.planId });
      //经销商简称
      // allData = Object.assign(allData, { dealerShortname: this.value.row.dealerName });
      //日志状态通过
      allData = Object.assign(allData, { reviewStatus: 25311009 });
      //项目计划总结状态 总结审核通过
      allData = Object.assign(allData, { planStatus: 25311009 });
      //经销商简称
      allData = Object.assign(allData, { dealerShortname: this.value.row.dealerShortname });

      let res = {};
      let res1 = {};
      console.log(allData);
      // if (allData.realApproveAmount == 0 || allData.realApproveAmount == null) {
      //   this.$notify.warning({ title: '提示信息', message: '事业部意见中实际批准金额必填!' });
      //   return;
      // }
      //如果支持方式为单店支持时，实际批准金额是否超过实际项目金额的70%，如果超过需要在审核时给予是否确认提示
      //实际项目金额
      let realProjectAmount = allData.row.realProjectAmount;
      //实际批准金额
      let realApproveAmount = allData.realApproveAmount;
      if (allData.row.cooperationMethod == types.COOPERATION_MODE_SINGLE) {
        //判断实际批准金额是否超过实际项目金额的70%
        if (parseFloat(realApproveAmount) / parseFloat(realProjectAmount) > 0.7) {
          this.$confirm('实际批准金额超过实际金额的70%，是否确认审核通过?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
            .then(async () => {
              this.passLoading = true;
              //保存事业部意见;
              res = await passCaseSummary(allData);
              //修改总结状态已通过
              res1 = await updateCaseSummaryPass(allData, this.value.row.planId);
              if (res.resultCode === 200 && res1.resultCode === 200) {
                this.passLoading = false;
                this.$notify.success({ title: '提示信息', message: '已通过!' });
                this.closeDialog('refresh');
              }
            })
            .catch(() => {});
          return;
        }
      }
      this.passLoading = true;
      //保存事业部意见
      res = await passCaseSummary(allData);
      //修改总结状态已通过
      res1 = await updateCaseSummaryPass(allData, this.value.row.planId);
      if (res.resultCode === 200 && res1.resultCode === 200) {
        this.passLoading = false;
        this.$notify.success({ title: '提示信息', message: '已通过!' });
        this.closeDialog('refresh');
      }
    },
    //取消操作
    closeDialog(param) {
      this.$emit('close', false, param);
    }
  }
};
</script>
<style scoped>
.wrapper {
  height: calc(100vh - 110px);
}
</style>
